package logic

import (
	"common"
	"common/grpcx"
	"common/zapx"
	"go.uber.org/zap"
	"swiper/internal/pb"
	"time"
)

// GetObjectFullUri 通过minio grpc获取完整的对象连接
func GetObjectFullUri(objectName string) string {
	conn, err := grpcx.NewNoCertConn("minio")
	if err != nil {
		zapx.Logger.Error("[GetObjectFullUri]连接minio grpc服务失败", zap.Error(err))
		return ""
	}
	defer conn.Close()
	minioClient := pb.NewMinioServiceClient(conn)
	ctx, cancel := common.WithTimeoutContext(time.Second * 2)
	defer cancel()
	res, err := minioClient.GetUrl(ctx, &pb.UrlRequest{
		Key: objectName,
	})
	if err != nil {
		zapx.Logger.Error("获取完整的连接失败", zap.Error(err))
		return ""
	}
	return res.Uri
}
